import path from 'path'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Inspect from 'vite-plugin-inspect'
import { fileURLToPath } from 'url'
import vueDevTools from 'vite-plugin-vue-devtools'

const pathSrc = path.resolve(__dirname, 'src')

export default defineConfig({
	plugins: [
		Vue(),
		vueDevTools(),
		AutoImport({
			resolvers: [
				ElementPlusResolver(),
			],
			
			imports: [], 
			dts: path.resolve(pathSrc, 'auto-imports.d.ts'),
		}),

		Components({
			resolvers: [
				IconsResolver({
					enabledCollections: ['ep'],
				}),
				ElementPlusResolver(),
			],
			
			// dirs: [], // 禁止自动扫描 components 目录
			dts: path.resolve(pathSrc, 'components.d.ts'),
		}),

		Icons({
			autoInstall: true,
		}),

		Inspect(),
	],
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src', import.meta.url))
		},
	},
	server: {
		proxy: {
			//将以/api开头的请求代理到目标服务器
			'/api': {
				target: 'http://localhost:8080',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, '')
			}
		},
	},
})

